using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public partial class DialogFloating : Floating
{
    string _title;
    public string Title
    {
        get => _title;
        set
        {
            _title = value;
            this.SetDirty();
        }
    }

    string _content;
    public string Content
    {
        get => _content;
        set
        {
            _content = value;
            this.SetDirty();
        }
    }

    public enum StyleType
    {
        ConfirmOnly,
        Ask,
    }


    StyleType _style;
    public StyleType Style
    {
        get => _style;
        set
        {
            _style = value;
            this.SetDirty();
        }
    }

    public Action<bool> onCompleted;

    protected override void Refresh()
    {
        this.RefreshTitle();
        this.RefreshContent();
        this.RefreshSolo();
    }

    void RefreshSolo()
    {
        if (this.Style == StyleType.ConfirmOnly)
        {
            this.Solo.SetChildActive(this.Group_confirmOnly.transform);
        }
        else if (this.Style == StyleType.Ask)
        {
            this.Solo.SetChildActive(this.Group_ask.transform);
        }
        else
        {
            throw new Exception("not support style " + this.Style);
        }

    }

    void RefreshContent()
    {
        this.Text_content.text = this.Content;
    }

    void RefreshTitle()
    {
        this.Text_title.text = this.Title;
    }

    public void OnButton(string msg)
    {
        if (msg == "ok")
        {
            UIEngine.Stuff.RemoveFloating<DialogFloating>();
            this.onCompleted?.Invoke(true);
        }
        else if (msg == "cancel")
        {
            UIEngine.Stuff.RemoveFloating<DialogFloating>();
            this.onCompleted?.Invoke(false);
        }
    }
}
